#include <cmath>
#include <iostream>
using namespace std;

int GetSX(int x) {
  int ret = 0;

  while (x) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n;
  int ans = -1;

  cin >> n;
  for (int sx = 1; sx <= 81; sx++) {
    long long x = (-sx + sqrt(sx * sx + 4 * n)) / 2;

    if (x * x + sx * x - n == 0 && GetSX(x) == sx) {
      ans = x;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}